<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="../../../common/taglibs.jsp"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<s:if
	test="@org.springside.modules.security.springsecurity.SpringSecurityUtils@getCurrentUserName() == 'anonymousUser'">
	<s:include value="/admin/login.jsp" />
</s:if>
<s:else>
	<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>编辑新闻</title>
<style type="text/css">
/*new_manage**********************************/
.new_manage{
  margin: 15px;
  border: 1px solid #ccc;
}
.new_manage .manage_massage{
  margin:0 185px;
}
.new_manage .manage_massage .manage_classify{
  position: relative;
  margin-top: 30px;
}
.new_manage .manage_massage label{
  position: absolute;
  left: -136px;
  float: left;
  display: inline-block;
  width: 120px;
  line-height: 27px;
  text-align: right;
  font-size: 16px;
  margin-right: 5px;
}
.new_manage .manage_massage .title{
  height: 32px;
  padding: 8px 10px;
  width: 100%;
  border: 1px solid #ccc;
} 
.new_manage .manage_massage .add_pic{
  float: left;
  width: 64%;
  height: 32px;
  padding: 1px 10px;
  margin-right: 15px;
  border: 1px solid #ccc;
}
.new_manage .manage_massage .time{
  float: left;
  width: 64%;
  height: 32px;
  padding: 5px 10px;
  margin-right: 15px;
  margin-top:2px;
  border: 1px solid #ccc;
}
.new_manage .manage_massage .forie{
	*margin-left:-200px;
	
}
.new_manage .manage_massage .add_file{
  display: inline-block;
  width: 84px;
  height: 35px;/* background: url(../images/body_button_add_p.png) no-repeat;*/ 
}
/*.new_manage .manage_massage .add_file:hover{
   background: url(../images/body_button_add_active_p.png) no-repeat; 
}*/
.new_manage .manage_massage .textarea{
  width: 100%;
  height:369px;
  padding: 10px;
}
#Submit{
  float: right;
  margin:14px 0 33px;
  width: 84px;
  height: 35px;
  background: url(../images/body_button_handup_p.png) no-repeat;
}
#Submit:hover{
  background: url(../images/body_button_hangup_active.png) no-repeat;
}
</style>
<link href="${ctx }/css/public.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="${ctx }/kindeditor-4.1.9/themes/simple/simple.css" />
<script charset="utf-8" src="${ctx }/kindeditor-4.1.9/kindeditor-min.js"></script>
<script charset="utf-8" src="${ctx }/kindeditor-4.1.9/lang/zh_CN.js"></script>
<script type="text/javascript" src="${ctx }/My97DatePicker/WdatePicker.js"></script> 
<script>
	var editor;
	KindEditor.ready(function(K) {
		editor = K.create('textarea[name="entity.details"]', {
			       cssPath : '${ctx}/kindeditor-4.1.9/plugins/code/prettify.css',
				uploadJson :  '${ctx}/kindeditor-4.1.9/jsp/upload_json.jsp',  
				themeType : 'simple',
				fillDescAfterUploadImage:true,
				items:   [ 'source', '|', 'undo', 'redo', '|', 'preview', 'cut', 'copy', 'paste',
        'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
        'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
        'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
        'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
        'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'hr', 'link', 'unlink', '|','filemanager','insertfile','image'] ,
				fileManagerJson : '${ctx}/kindeditor-4.1.9/jsp/file_manager_json.jsp',
				allowFileManager : true,
				afterCreate : function() {
					var self = this;
					K.ctrl(document, 13, function() {
						self.sync();
						document.forms['article'].submit();
					});
					K.ctrl(self.edit.doc, 13, function() {
						self.sync();
						document.forms['ar7ticle'].submit();
					});
				}
			});
		});
		</script>
</head>

<body>
	<div class="main">
		<div class="tip">
      <span>所在位置 :</span>
      <span class="current_position">图片新闻管理</span>   
    </div>
    <div class="new_manage">

      <!-- 为form表单添加一个id -->
     <form  action="${ctx }/admin/newsphoto-admin!save.action?id=${id} "
				method="post" enctype="multipart/form-data" onsubmit="return check();">
	<input type="hidden" name="entity.shownew" id="latestReading"/>
		<input type="hidden" name="entity.showred" id="latestAnnouncement"/>

      <!-- 表单 -->
        <div class="manage_massage">
          <div class="manage_classify">
            <label for="title">标题 :</label>
            <input type="text" class="title" maxlength="50" id="title" name="entity.title" value="${entity.title}"/>
           
          </div>


          <!-- input hidden id判断是新建还是编辑 -->
          <input type="hidden" id="${id }" class="judge_picture" />
          
          <div class="manage_classify clearfix">
            <label for="add_pic">添加轮播图片 :</label>
            <span class="add_pic_content">
             <input type="text" id="add_pic" disabled="disabled" class="add_pic" value="${entity.picturepath}"/>
             
            <%--  <a class="add_file add_pic_file" type="file" name="pictruepath"></a>  --%>
        <input type="file" id="add_pic_file" name="pictruepath"class="add_file add_pic_file" style="_width:65px;*width:65px;width:67px;"  value="${entity.picturepath}" >  
            </span>
          </div> 
           <div class="manage_classify clearfix">
              <label for="time">发布时间 :</label>
              <input type="text" name="entity.editTime" class="time forie" onClick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" id="time" value="${entity.editTime}${time }"/>
          </div>
          <input type="checkbox" id="reading" <s:if test="entity.shownew==1"> checked="checked"</s:if>  />是否标示new
						<input type="checkbox" id="announcement" <s:if test="entity.showred==1"> checked="checked"</s:if> />字体是否变红
          <div class="manage_classify clearfix">

            <label for="textarea">正文 :</label>
            <textarea id="textarea" class="textarea" name="entity.details" >${entity.details}</textarea>
            
             <input type="submit" id="Submit" value="" style="border:none;" /> 
           
          </div>
        </div>

        
      </form>
    </div>
	</div>
  <script type="text/javascript" src="${ctx }/js/public.js"></script>
  <script type="text/javascript">
    add_file(["add_pic_file"]);

    var add_pic_file = newdom.$("add_pic_file"),
      add_pic = newdom.$("add_pic");


    //图片判别类型
   var hash = {
			'.png' : 1,
			'.jpg' : 1,
			'.gif' : 1,/* ,
			'.bmp' : 1 */
			'.JPG' : 1,
			'.GIF' : 1,
			'.PNG' : 1
		};
    add_pic_file.onchange = function(evt){
        var re = /\..+$/;
        var ext = this.value.match(re);
        if (hash[ext]) {
          if(document.all){
            // var fso = new ActiveXObject('Scripting.FileSystemObject'); 
            // var file = fso.GetFile(this.value);
            add_pic.value = this.value;
          }
          else{
            // var files = evt.target.files[0];
            add_pic.value = this.value;
          }
          
        } 
        else {
          alert("只能输入gif、png或者jpg格式的图片");
          this.value = "";
          add_pic.value = "";
        }
    }

    //点击提交按钮，表单提交 这里需要一个接口上传数据
    var add_file_textarea = newdom.getElementsByClass("add_file_textarea")[0],
      judge_picture = newdom.getElementsByClass("judge_picture")[0];//judge_picture是隐藏input来判断是否有id，以便判断处于编辑还是新建
    function check(){
      var announcementCheckbox = document.getElementById("announcement");
		var readingCheckbox = document.getElementById("reading");
		var announcementInput = document.getElementById("latestAnnouncement");
		var readingInput = document.getElementById("latestReading");
		if(announcementCheckbox.checked){
			announcementInput.value="1";
		}else{
			announcementInput.value="0";
		}
		if(readingCheckbox.checked){
			readingInput.value="1";
		}else{
			readingInput.value="0";
		}
     var arr = is_empty(["title" ],["标题" ]),//传id字符串
     
        len_arr = arr.length;
        var time=document.getElementById("time");
        if(len_arr != 0 || !judge_picture.id){
            for (var i = 0; i < len_arr; i++) {
              alert(arr[i] + "不能为空");
              return false ;
            };
        if(editor.isEmpty()){
			alert("正文不能为空！");
			return false;
		}
        if(time.value==""){
        	alert("发布时间不能为空！");
        return false;}
     
        //图片编辑多出的判断部分
          if(!add_pic_file.value){
          alert("图片不能为空");
        }  
        else{
          //表单提交改成这样
          return len_arr > 0 ? false : true;
        } 
        return false;
      }
      else{
        //表单提交改成这样
      /*   if(!add_pic_file.value){
            alert("图片不能为空");
            return false;
        }  
        else{
          //表单提交改成这样
          return true;
        } */
      }
    
    }
    
function add_file(options){
  var len_add = options.length,
      arr_class = [],
      arr_id = [];

  for(var i = 0;i < len_add;i++){
    arr_class[i] = newdom.getElementsByClass(options[i])[0];
    arr_class[i].index = i;
    arr_id[i] = newdom.$(options[i]);

   
  }
}
  </script>
</body>
</html>
</s:else>








